package com.otoe.dilidilivid.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.otoe.dilidilivid.R;
import com.otoe.dilidilivid.data.entity.Review;

import java.util.List;

public class ReviewAdapter extends RecyclerView.Adapter<ReviewAdapter.VH> {
    List<Review> reviewList;
    public static class VH extends RecyclerView.ViewHolder{
        public TextView textView;
        public VH(View v){
            super(v);
            textView=v.findViewById(R.id.viewTextView);
        }
    }
    public ReviewAdapter(){

    }
    public ReviewAdapter(List<Review> reviewList){
        this.reviewList=reviewList;
    }
    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View v = View.inflate(parent.getContext(), R.layout.view_list, null);
        return new VH(v);
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        holder.textView.setText(reviewList.get(position).getTxt());
    }

    @Override
    public int getItemCount() {
        return reviewList.size();
    }

    public void addItem(String text){
        reviewList.add(0,new Review(text));
//        notifyItemChanged(0);
        notifyItemInserted(0);
    }

}
